package com.img.examine.service.Impl;

import com.img.examine.entity.EmployeeEntity;
import com.img.examine.entity.StudentEntity;
import com.img.examine.mapper.EmployeeMapper;
import com.img.examine.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
    EmployeeMapper employeeMapper;
    @Override
    public ArrayList<EmployeeEntity> getEmployee(String key_id, String name, Integer update_time) {
        key_id="%"+key_id.replaceAll(" ","%")+"%";
        name="%"+name.replaceAll(" ","%")+"%";
        if(update_time == 0){
            return employeeMapper.getEmployeeAll(key_id, name);
        }
        String update_time2[] = getInteger(update_time);
        return employeeMapper.getEmployee(key_id, name, update_time2[0],update_time2[1]);
    }

    @Override
    public boolean setEmployeeIcon(String KEY_ID) {
        return employeeMapper.setEmployeeIcon(KEY_ID)>0;
    }

    static String[] getInteger(Integer update_time) {
        String[] time= new String[2];
        SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmss");
        //获取今天的时间
        String date = sdf.format(new Date());
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(new Date());
        String date2 = null;
        if(update_time==1){
            calendar.add(calendar.DATE,-1);
            date2 =sdf.format(calendar.getTime());
        }
        if(update_time==2){
            calendar.add(calendar.DATE,-7);
            date2 =sdf.format(calendar.getTime());
        }
        if(update_time==3){
            calendar.add(calendar.DATE,-30);
            date2 =sdf.format(calendar.getTime());
        }
        if(update_time==4){
            calendar.add(calendar.DATE,-183);
            date2 =sdf.format(calendar.getTime());
        }
        if(update_time==5){
            calendar.add(calendar.YEAR,-1);
            date2 =sdf.format(calendar.getTime());
        }
        time[0]=date+"0000";
        time[1]=date2+"0000";
        return time;
    }
}
